//
//  ReleaseMainTagCell.m
//  ShowYork
//
//  Created by hxh on 2020/12/21.
//  Copyright © 2020 hxh. All rights reserved.
//

#import "DynamicMainTopicCell.h"

@interface DynamicMainTopicCell ()
@property (nonatomic,strong)UIButton *nameButton;
@end

@implementation DynamicMainTopicCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setUI];
    }
    return self;
}

- (void)setUI{
    
    self.backgroundColor = C21;
    
    self.nameButton = [[UIButton alloc]init];
    self.nameButton.backgroundColor = C21;
    [self.nameButton setTitle:@"热门话题" forState:UIControlStateNormal];
    [self.nameButton setTitleColor:C51 forState:UIControlStateNormal];
    [self.nameButton setTitleColor:RGBA(245, 75, 100, 1) forState:UIControlStateSelected];
    self.nameButton.titleLabel.font = font(16);
    self.nameButton.titleLabel.lineBreakMode = NSLineBreakByClipping;
    [self.nameButton addTarget:self action:@selector(nameMethod) forControlEvents:UIControlEventTouchUpInside];
    self.nameButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    [self.contentView addSubview:self.nameButton];
    [self.nameButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(24);
        make.right.equalTo(self.contentView).offset(-20);
        make.top.bottom.equalTo(self.contentView);
        make.height.mas_equalTo(44).priorityHigh();
    }];
}

- (void)nameMethod{
    if (self.delegate && [self.delegate respondsToSelector:@selector(updateCurrentTopicListWithItemModel:)]) {
        [self.delegate updateCurrentTopicListWithItemModel:self.model];
    }
}

+(instancetype)cellWithTableView:(UITableView *)tableView{
    NSString *ID = @"DynamicMainTopicCell";
    DynamicMainTopicCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (!cell) {
        cell = [[DynamicMainTopicCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return cell;
}
-(void)setModel:(SocialMainTopicModel *)model{
    _model = model;
    [self.nameButton setTitle:model.topicName forState:UIControlStateNormal];
    self.nameButton.selected = model.isSelected;
    if (model.isSelected) {
        self.nameButton.backgroundColor = [UIColor whiteColor];
        self.backgroundColor = [UIColor whiteColor];
    }else{
        self.nameButton.backgroundColor = RGBA(248, 248, 248, 1);
        self.backgroundColor = RGBA(248, 248, 248, 1);
    }
}

@end
